;(function () {
	new Vue({
		el: '#jwk-list',
		data () {
			return {
				power: JSON.parse(localStorage.getItem('permissions')),
				menuData: [
					{name: '待处理', code: 'TBA', num: 0},
					{name: '已成交', code: 'DAL', num: 0},
					{name: '已关闭', code: 'CLS', num: 0},
				],
				selectedData: [],
				page: 1,
				limit: ['10'],
				limitCount: [
					{name: '10', code: '10'},
					{name: '15', code: '15'},
					{name: '20', code: '20'}
				],
				parkList: [],
				parkInfo: {},
				cityList: [],
				selectCityData: [],
				districtList: [],
				selectDistrictData: [],
				column: '#',
				order: '#',
				isSuccesDialog: false,
				isErrorDialog: false,
				successText: '',
				errorText: '',
				isExtenseFlag: false,
				keyword: '',
				orderStartDate: '',
				orderEndDate: '',
				submitStartDate: '',
				submitEndDate: '',
				dataObj: {},
				appointmentId: '',
				//滚动条配置
				scrollDisx: 0,
				rowIndex: '',
				ops: {
				  bar: {
				    background: '#000',
						onlyShowBarOnScroll: false,
						keepShow: false,
						hoverStyle: false,
						size: '10px',
						opacity: 0.3
				  },
					scrollPanel: {
						scrollingX: true,
						scrollingY: false
					}
				}
			}
		},
		filters: {
			formatDate: function (time) {
			  if (time === undefined) return '--'
			  return hlDateUtil.formatUTCDate(time, 'yyyy-MM-dd')
			},
		},
		methods: {
			selectParkId(val) {
				this.parkInfo = val
			},
			// 获取园区数据
			getParkData(val, callback) {
				this.parkInfo = {
					name:val,
					id:'#'
				}
				var that = this;
				hlhttp.get({
					url: 'jwk/park_info/_search',
					data: {
						keyword: val || '#'
					},
					success: data => {
						callback(data)
					}
				})
			},
			//预约列表
			officeAppointmentsList () {
				hlhttp.get({
					url: 'jwk/office_appointments',
					data: {
						keyword: this.keyword ? this.keyword : '#',
						park_id: this.parkInfo.id ? this.parkInfo.id : '#',
						park_name: this.parkInfo.name ? this.parkInfo.name : '#',
						city_code: this.selectCityData.length ? this.selectCityData[0] : '#',
						district_code: this.selectDistrictData.length ? this.selectDistrictData[0] : '#',
						begin_appointment_time: this.orderStartDate ? this.orderStartDate : '#',
						end_appointment_time: this.orderEndDate ? this.orderEndDate : '#',
						begin_submit_time: this.submitStartDate ? this.submitStartDate : '#',
						end_submit_time: this.submitEndDate ? this.submitEndDate : '#',
						status: this.selectedData.length ? this.selectedData[0] : '#',
						page: this.page,
						limit: this.limit[0],
						column: this.column,
						order: this.order
					},
					success: (res) => {
						this.dataObj = res;
					}
				})
			},
			officeAppointmentStatus () {
				hlhttp.get({
					url: 'jwk/office_appointment_status/_statistics',
					data: {
						keyword: this.keyword ? this.keyword : '#',
						park_id: this.parkInfo.id ? this.parkInfo.id : '#',
						park_name: this.parkInfo.id ? this.parkInfo.id : '#',
						city_code: this.selectCityData.length ? this.selectCityData[0] : '#',
						district_code: this.selectDistrictData.length ? this.selectDistrictData[0] : '#',
						begin_appointment_time: this.orderStartDate ? this.orderStartDate : '#',
						end_appointment_time: this.orderEndDate ? this.orderEndDate : '#',
						begin_submit_time: this.submitStartDate ? this.submitStartDate : '#',
						end_submit_time: this.submitEndDate ? this.submitEndDate : '#'
					},
					success: (res) => {
						this.menuData[0].num = res.TBA;
						this.menuData[1].num = res.DAL;
						this.menuData[2].num = res.CLS;
					}
				})
			},
			//目录
			selectCheckbox () {
				this.officeAppointmentsList()
			},
			resetMenu () {
				this.selectedData = [];
				this.officeAppointmentsList()
			},
			//日期排序
			sortDate (type) {
				this.column = type;
				this.order = this.order == 'A' ? 'D' : 'A';
				this.officeAppointmentsList()
			},
			//数量控制
			limitCountSet (arr) {
				this.limit = [arr[0].code]
				this.officeAppointmentsList()
			},
			//翻页
			pagination (num) {
				this.page = num;
				this.officeAppointmentsList()
			},
			//成交框框
			isShowKuanKuan (id) {
				this.isSuccesDialog = !this.isSuccesDialog;
				if (this.isSuccesDialog) {
					this.appointmentId = id
				}
				if (!this.isSuccesDialog) {
					this.successText = ''
				}
			},
			//关闭框框
			isErrorKK (id) {
				this.isErrorDialog = !this.isErrorDialog;
				if (this.isErrorDialog) {
					this.appointmentId = id
				}
				if (!this.isErrorDialog) {
					this.errorText = ''
				}
			},
			//提交成功
			submitSuccess () {
				hlhttp.put({
					url: 'jwk/office_appointment/_deal',
					data: {
						appointment_id: this.appointmentId,
						memo: this.successText
					},
					success: () => {
						hl.toast('操作成功')
						this.isShowKuanKuan()
						this.officeAppointmentsList()
						this.officeAppointmentStatus()
					}
				})
			},
			//提交关闭
			submitError () {
				if (!this.errorText) {
					hl.toast('失败原因必填')
					return
				}
				hlhttp.put({
					url: 'jwk/office_appointment/_close',
					data: {
						appointment_id: this.appointmentId,
						memo: this.errorText
					},
					success: () => {
						hl.toast('操作成功')
						this.isErrorKK()
						this.officeAppointmentsList()
						this.officeAppointmentStatus()
					}
				})
			},
			//搜索
			querySearch () {
				this.officeAppointmentsList()
				this.officeAppointmentStatus()
			},
			//重置
			resetSearch () {
				this.keyword = '';
				this.orderStartDate = '';
				this.orderEndDate = '';
				this.submitStartDate = '';
				this.submitEndDate = '';
				this.selectedData = [];
				this.parkInfo = {}
				this.page = 1;
				this.limit = ['10'];
				this.column = '#';
				this.order = '#';
				this.selectParkData = [];
				this.selectCityData = [];
				this.selectDistrictData = [];
				this.districtList = [];
				this.officeAppointmentsList()
				this.officeAppointmentStatus()
			},
			//园区
			parkApi () {
				hlhttp.get({
					url: 'jwk/park_info/_search',
					data: {
						keyword: '#'
					},
					success: data => {
						data.map(item => {
							item.code = item.id
						})
						this.parkList = data
					}
				})
			},
			//区域
			regionCityApi () {
				hlhttp.get({
					url: 'configure/dict',
					data: {module_code : 'CSTM_JWK', config_name: 'CSTM_JWK_REGION_CITY'}, //parent_dict_code: ''
					success: (res) => {
						res.map(item => {
							item.name = item.dictName;
							item.code = item.dictCode;
						})
						this.cityList = res;
					}
				})
			},
			//区域
			regionDistrictApi () {
				hlhttp.get({
					url: 'configure/dict',
					data: {module_code : 'CSTM_JWK', config_name: 'CSTM_JWK_REGION_DISTRICT', parent_dict_code: this.selectCityData.length ? this.selectCityData[0] : '#'},
					success: (res) => {
						res.map(item => {
							item.name = item.dictName;
							item.code = item.dictCode;
						})
						this.districtList = res;
					}
				})
			},
			//选择园区
			selectPark (arr) {
				this.selectParkData = [arr[0]['code']]
			},
			//选择城市
			selectCity (arr) {
				this.selectCityData = [arr[0]['code']]
				this.regionDistrictApi()
			},
			//选择地区
			selectDistrict (arr) {
				this.selectDistrictData = [arr[0]['code']]
			},

			openSearch () {
				this.isExtenseFlag = !this.isExtenseFlag
			},
			handleComplete(vertical, horizontal) {
				this.scrollDisx = horizontal.process*100
			},
			toCreateWorkPage () {
				hlUrlUtil.goTo('jwkWrokAddEdit',{ddtab:true, mode: 'create'}, true)
			},
			toCreateRegionPage () {
				hlUrlUtil.goTo('jwkRegionConfig',{ddtab:true, mode: 'create'}, true)
			},
			toCreateMatchingPage () {
				hlUrlUtil.goTo('jwkMatching',{ddtab:true, mode: 'create'}, true)
			},
			toCreateParkPage () {
				hlUrlUtil.goTo('jwkPark',{ddtab:true, mode: 'create'}, true)
			},
			toDetailPage (obj) {
				hlUrlUtil.goTo('jwkOrderDetail', {ddtab:true, mode: 'detail', id: obj.id}, true)
			},
			//滚动初始化
			rollInit () {
				const self = this;
				let disx = 0;
				function scrollFunc (e, ref){
					e=e||window.event;
					if (e&&e.preventDefault){
						if (e.deltaY > 0) {
							disx += 10
						}
						if (e.deltaY < 0) {
							disx -= 10
						}
						if (disx > 100) {disx=100}
						if (disx < 0) {disx = 0}
						self.$refs[ref].scrollTo(
							{
								x: disx + '%'
							},
							10
						);
						e.preventDefault();
						e.stopPropagation();
					}else{
					 e.returnvalue=false;
					 return false;
					}
				}

				document.querySelector('.hl-scroll-container').onmouseenter = function () {
					disx = self.scrollDisx;
					scrollLeft('.hl-scroll-container', 'scrollWrap')
				}

				document.querySelector('.hl-scroll-container').onmouseleave = function () {
					document.querySelector('.hl-scroll-container').onmousewheel = null;
				};

				function scrollLeft (className, ref) {
					function addEventListFn(e) {scrollFunc(e, ref)}
					document.querySelector(className).onmousewheel = addEventListFn
				}
			}
		},
		mounted () {
			let style = document.createElement('style')
			style.innerHTML = `
				.__vuescroll .__panel{overflow:hidden !important}
			`
			this.$refs.vs.appendChild(style)
			this.rollInit()

			this.officeAppointmentsList()
			this.officeAppointmentStatus()
			this.parkApi()
			this.regionCityApi()
		}
	})
} ())
